#! /bin/bash

ns=$1
app=$2
if test -z "$sh"; then
    sh=bash
fi

IFS=$'\n'
pods=($(kubectl -n$ns get pods | grep $app))
echo $pods
podc=${#pods[*]}
if test $podc -eq 0; then
    echo "pods not found"
fi

if test $podc -gt 1; then
    for i in $(seq $podc); do
        i=`expr $i - 1`
        echo "$i ${pods[$i]}"
    done
    read choose
    pods=${pods[$choose]}
fi
pods=`echo $pods | awk '{print $1}'`
echo "Selected pod: $pods"

shift 2
echo "kubectl -n$ns exec -it $pods $@"
kubectl -n$ns exec -it $pods $@
